#!/usr/bin/env/python3
# coding:utf-8
"""
# @Time    : 2022/1/14 16:58
# @Author  : feifeigao
# @File    : 1984.py
"""
"""
1984:
[题意]
学生分数的最小差值。
从数组中选出任意 k 名学生的分数，使这 k 个分数间 最高分 和 最低分 的 差值 达到 最小化 。
[思路题解]


[解题步骤]

[经典代码模板]

[tips]

[注意]


"""
def a(nums,k):
    # n=len(nums)
    # nums.sort(reverse=True)
    # print(nums)
    # sub=nums[0]-nums[:k-1]
    # print(sub)
    # return sub
    nums.sort()
    print(nums)
    for i, j in zip(nums, nums[k-1:]):
        print(j-i)
    return min(j - i for i, j in zip(nums, nums[k - 1:]))




if __name__ == '__main__':
    nums = [9, 4, 1, 7]
    # k = 2

    nums=[41900, 69441, 94407, 37498, ]
    # 2231, 54526, 79072, 84309, 76765, 92282, 13401, 44698, 17586,
    #  98455, 47895, 98889, 65298, 32271, 23801, 83153, 12186, 7453, 79460, 67209, 54576, 87785, 47738, 40750, 31265,
    #  77990, 93502, 50364, 75098, 11712, 80013, 24193, 35209, 56300, 85735, 3590, 24858, 6780, 50086, 87549, 7413, 90444,
    #  12284, 44970, 39274, 81201, 43353, 75808, 14508, 17389, 10313, 90055, 43102, 18659, 20802, 70315, 48843, 12273,
    #  78876, 36638, 17051, 20478
    k=3
    r=a(nums,k)
    # print(r)
